local RoomBase = require 'packages.hearthstone.battlegrounds.core.roombase'

---@class Hearthstone.Room : Hearthstone.RoomBase, ServerRoomBase
local Room = RoomBase:subclass("Hearthstone.Room")

Room:include(Fk.Base.ServerRoomBase)

local GameLogic = require "packages.hearthstone.battlegrounds.server.gamelogic"
local ServerPlayer = require "packages.hearthstone.battlegrounds.server.serverplayer"

function Room:initialize(_room)
  RoomBase.initialize(self)
  Fk.Base.ServerRoomBase.initialize(self, _room)

  self.serverplayer_klass = ServerPlayer
  self.logic_klass = GameLogic

  self.ground_maxlevel = 6
  self.shop_cards = {}--商店卡牌
  self:loadShopCards()
end


--加载商店卡牌，按等级加载
function Room:loadShopCards()
  self.shop_cards = {}
  for _, card in pairs(hs.cards) do
    local level = tavern_level or 1
    self.shop_cards[level] = self.shop_cards[level] or {}
    table.insert(self.shop_cards[level], card)
  end
end




--获取商店的卡牌
--@param player Player
--@param num integer 刷新的卡牌数
function Room:getShopCards(player, num)
  local shop_maxcards = player.shop_maxcards or 3
  local old_cards = table.filter(player.shop, function(card) return card.frozen end)
  local num = shop_maxcards - #old_cards
  local new_cards = {}
  if num > 0 then
    new_cards = table.random(self.shop_cards[player.tavern_level], num)
  end
  return new_cards
end

--刷新玩家商店的卡牌
--@param player Player
function Room:refreshShopCards(player)
  local players = self.currentPlayers
  local shop_maxcards = player.shop_maxcards
  local old_cards = table.filter(player.shop_cards, function(card) return card.lock end)
  local num = shop_maxcards - #old_cards
  local new_cards = {}
  if num > 0 then
  player.shop_cards = new_cards
  end
end



return Room